package com.slipper.system.flow.controller;

import com.slipper.constants.FlowConstants;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.slipper.system.flow.bo.FlowPendingBO;
import com.slipper.system.flow.service.FlowPendingService;
import com.slipper.constants.Constants;
import com.slipper.common.bo.UserDetail;
import com.slipper.util.ResultUtil;

/**
 * 流程待办表
 */
@RestController
@RequestMapping("/system/flowPending")
public class FlowPendingController {
    @Resource
    private FlowPendingService flowPendingService;

    @PostMapping("/queryBy")
    public String queryBy(@RequestBody FlowPendingBO bo) {
        return ResultUtil.successResult(flowPendingService.queryBy(bo.getId()));
    }

    @PostMapping("/queryPendingPage")
    public String queryPendingPage(@RequestBody FlowPendingBO bo) {
        UserDetail userDetail = Constants.getCurrentUser();
        bo.setCurrManId(userDetail.getEmployeeId());
        bo.setCurrOrgId(userDetail.getOrgId());
        bo.setCurrUnitId(userDetail.getUnitId());
        bo.setStatus(FlowConstants.FlowPending.STATUS_PENDING);
        return ResultUtil.successResult(flowPendingService.queryPage(bo));
    }

    @PostMapping("/queryPendedPage")
    public String queryPendedPage(@RequestBody FlowPendingBO bo) {
        UserDetail userDetail = Constants.getCurrentUser();
        bo.setCurrManId(userDetail.getEmployeeId());
        bo.setStatus(FlowConstants.FlowPending.STATUS_FINISHED);
        return ResultUtil.successResult(flowPendingService.queryPage(bo));
    }

    @PostMapping("/save")
    public String save(@RequestBody FlowPendingBO bo) {
        return ResultUtil.successResult(flowPendingService.save(bo));
    }

    @PostMapping("/delete")
    public String delete(@RequestBody FlowPendingBO bo) {
        return ResultUtil.successResult(flowPendingService.delete(bo));
    }
}
